#include <stdio.h>
#include <string.h>

#include <irt_syscalls.h>

char out[] = "Hello World.\n";

_irt_syscalls_t   fake_irt;
_irt_syscalls_t** dl_ptr;

_irt_syscalls_t** dl_irt_ptr(void);

int main(int argc, char* argv[]) {
	size_t outlen = strlen(out);
	size_t written = 0;

	if (g_nacl_irt_syscalls_ptr == NULL)
		return 1;

  int err = __nacl_irt_write(1, out, outlen, &written);
	if (err != 0)
		return 2;
	if (written != outlen)
		return 3;

	dl_ptr = dl_irt_ptr();
	if (dl_ptr == &g_nacl_irt_syscalls_ptr)
		return 4;

	printf("Success - %s.\n", argv[0]);
	return 0;
}